#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e7+10;

int a[N],n,top,stk[N],ls[N],rs[N];

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	for(int i = 1;i <= n;i++){
		a[i] = in;int pos = top;
		while(pos && a[stk[pos]] > a[i]) pos--;
		if(pos) rs[stk[pos]] = i;
		if(pos < top) ls[i] = stk[pos+1];
		stk[top=++pos] = i;
	}
	ll ansl = 0,ansr = 0;
	for(int i = 1;i <= n;i++) ansl ^= 1ll * i * (ls[i] + 1),ansr ^= 1ll * i * (rs[i] + 1);
	printf("%lld %lld\n",ansl,ansr);
	return 0;
}

